package com.homejoy.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.homejoy.system.domain.vo.HomeJoyPropertyVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.homejoy.common.annotation.Log;
import com.homejoy.common.core.controller.BaseController;
import com.homejoy.common.core.domain.AjaxResult;
import com.homejoy.common.enums.BusinessType;
import com.homejoy.system.domain.HomejoyProperty;
import com.homejoy.system.service.IHomejoyPropertyService;
import com.homejoy.common.utils.poi.ExcelUtil;
import com.homejoy.common.core.page.TableDataInfo;

/**
 * 房源基础信息Controller
 *
 * @author homeJoy
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/system/property")
public class HomejoyPropertyController extends BaseController {

    @Autowired
    private IHomejoyPropertyService homejoyPropertyService;

    /**
     * 查询房源基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:property:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomejoyProperty homejoyProperty) {
        startPage();
        List<HomeJoyPropertyVo> list = homejoyPropertyService.selectHomeJoyPropertyVoList(homejoyProperty);
        return getDataTable(list);
    }

    /**
     * 导出房源基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:property:export')")
    @Log(title = "房源基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomejoyProperty homejoyProperty) {
        List<HomejoyProperty> list = homejoyPropertyService.selectHomejoyPropertyList(homejoyProperty);
        ExcelUtil<HomejoyProperty> util = new ExcelUtil<HomejoyProperty>(HomejoyProperty.class);
        util.exportExcel(response, list, "房源基础信息数据");
    }

    /**
     * 获取房源基础信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:property:query')")
    @GetMapping(value = "/{propertyId}")
    public AjaxResult getInfo(@PathVariable("propertyId") Long propertyId) {
        return success(homejoyPropertyService.selectHomejoyPropertyByPropertyId(propertyId));
    }

    /**
     * 新增房源基础信息
     */
    @PreAuthorize("@ss.hasPermi('system:property:add')")
    @Log(title = "房源基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomejoyProperty homejoyProperty) {
        return toAjax(homejoyPropertyService.insertHomejoyProperty(homejoyProperty));
    }

    /**
     * 修改房源基础信息
     */
    @PreAuthorize("@ss.hasPermi('system:property:edit')")
    @Log(title = "房源基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomejoyProperty homejoyProperty) {
        return toAjax(homejoyPropertyService.updateHomejoyProperty(homejoyProperty));
    }

    /**
     * 删除房源基础信息
     */
    @PreAuthorize("@ss.hasPermi('system:property:remove')")
    @Log(title = "房源基础信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{propertyIds}")
    public AjaxResult remove(@PathVariable Long[] propertyIds) {
        return toAjax(homejoyPropertyService.deleteHomejoyPropertyByPropertyIds(propertyIds));
    }
}
